package com.coldwindblows.blog.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.coldwindblows.blog.constant.WebConst;
import com.coldwindblows.blog.dao.LogMapper;
import com.coldwindblows.blog.pojo.LogDo;
import com.coldwindblows.blog.service.ILogService;
import com.github.pagehelper.PageHelper;

/**
 * Created by ColdWindBlows on 2018/07/04
 *
 */
@Service
public class ILogServiceImpl implements ILogService {

	@Autowired
	private LogMapper logDao;
	
	@Override
	public boolean insertLog(LogDo log) {
		return logDao.insert(log) > 0;
	}

	@Override
	public boolean insertLog(String action, String data, String ip, Integer authorId) {
		LogDo logs= new LogDo();
		logs.setAction(action);
		logs.setData(data);
		logs.setIp(ip);
		logs.setAuthorId(authorId);
		logs.setCreated(new Date());
		
		return logDao.insert(logs) > 0;
	}

	@Override
	public List<LogDo> getLogs(int page, int pageSize) {
		pageSize = pageSize < 1 || pageSize > WebConst.MAX_POSTS ? 10 : pageSize;
		PageHelper.startPage(page, pageSize);
		
		return logDao.listAll();
	}

}
